﻿using NUnit.Framework;
using System.Linq;
using StreetPacMan.Server.Facade;

namespace StreetPacMan.Server.Tests.Integ
{
    [TestFixture]
    public class InjectingGameMessage : BddBase
    {
        private readonly IServerFacade ServerFacade;
        private readonly JoinGameResult Pacman;

        public InjectingGameMessage()
        {
            ServerFacade = ServerFacadeFactory.GetServerFacade();

            ServerFacade.CreateGameX("GameName");
            Pacman = ServerFacade.JoinGameX("GameName", "PacManName", PlayerRole.PacMan);
            ServerFacade.SendGameMessage(new SendGameMessageParameters(Pacman.PlayerId, "Injected Message"));
        }

        [Test]
        public void LastGameMessageShouldBeTheInjectedOne()
        {
            Assert.AreEqual("Injected Message", ServerFacade.GetGameStateAsObvserverX("GameName").LastGameMessage);
        }

        [Test]
        public void EventShouldBeAdded()
        {
            Assert.AreEqual("PacManName said 'Injected Message'", ServerFacade.GetAllEventsX("GameName").Events.Last().Description);
        }

        [Test]
        public void MessagesArrayShouldContainIt()
        {
            var clientMessages = ServerFacade.UpdateMyWhereabouts(new ServerPollParameters(Pacman.PlayerId,9,9,true)).RecentMessages;
            Assert.IsTrue(clientMessages.Select(x => x.Body).Contains("Injected Message"));
        }
    }
}